package com.abel.repository.helper;

import java.sql.Connection;
import java.sql.Statement;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class DataSourceTester {

	/**
	 * @param args
	 */
	public static void test() {

		Connection conn = null;
        Statement stmt = null;
		
		try {
			InitialContext ctx = new InitialContext();
			Context envCtx = (Context) ctx.lookup("java:comp/env");
			DataSource ds = (DataSource)envCtx.lookup("jdbc/AbelDS");
            conn = ds.getConnection();
            stmt = conn.createStatement();
            stmt.execute("select * from applicant;");
            stmt.close();
            stmt = null;
            conn.close();
            conn = null;
        }
		catch (Exception e) {
			System.out.println(e);
			e.printStackTrace();
		}
		finally {
        	if (stmt != null) {
                try {
                    stmt.close();
                } catch (Exception sqlex) {
                    // ignore -- as we can't do anything about it here
                }

                stmt = null;
            }

            if (conn != null) {
                try {
                    conn.close();
                } catch (Exception sqlex) {
                    // ignore -- as we can't do anything about it here
                }

                conn = null;
            }
        }
    }

}
